package top.lixunda.ecommerce.server.user.api.entity.vo;

import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.user.api.entity.db.BusinessTaskDO;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 代办任务返回结果VO，返回代办事项任务，包括任务本身以及个人任务
 *
 * @author lixunda
 * @version time:2020/4/13 14:00
 */
@ApiModel(value = "代办任务返回结果VO", description = "返回代办事项任务，包括任务本身以及个人任务")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class BusinessTaskVO extends BusinessTaskDO {

    /**
     * 代办任务子项，每个子项的人员不同
     */
    private List<BusinessTaskItemVO> businessTaskItemList;

    /**
     * 数据转换
     *
     * @param businessTaskDO BusinessTaskDO
     * @return BusinessTaskVO
     */
    public static BusinessTaskVO fromBusinessTaskDO(BusinessTaskDO businessTaskDO) {
        if (ObjectValidators.isEmpty(businessTaskDO)) {
            return null;
        }
        BusinessTaskVO temp = new BusinessTaskVO();
        BeanUtils.copyProperties(businessTaskDO, temp);
        return temp;
    }

    /**
     * 数据转换
     *
     * @param list BusinessTaskDO列表
     * @return BusinessTaskVO列表
     */
    public static List<BusinessTaskVO> fromBusinessTaskDO(Collection<BusinessTaskDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(BusinessTaskVO::fromBusinessTaskDO)
                .collect(Collectors.toList());
    }

}
